﻿using Autofac;
using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Hosting;
using TemplateApiCore.Config;


namespace TemplateApiCore
{
    /// <summary>
    /// Autofac扩展
    /// </summary>
    public static class AutofacExtension
    {
        /// <summary>
        /// <summary>
        /// 添加Autofac扩展
        /// </summary>
        /// </summary>
        /// <param name="builder"></param>
        public static void AddAutofacExtension(this WebApplicationBuilder builder)
        {
            //1、NuGet package: Autofac
            //2、NuGet package: Autofac.Extensions.DependencyInjection
            builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
            builder.Host.ConfigureContainer<ContainerBuilder>(container =>
            {
                #region 通过模块化的方式注册接口层和实现层
                container.RegisterModule(new AutofacModuleRegister());
                #endregion
            });
        }
    }
}
